<script setup lang="ts">
import {onMounted, ref} from 'vue'
import ExamDialog from "../../../components/subassembly/ExamDialog.vue";
import {$franchise, $franchiseById, $hotelExamById} from "../../../api/exam.ts";
import ShowDialog from "../../../components/subassembly/ShowDialog.vue";
import {ElNotification} from "element-plus";

const dialogRef = ref(false)
const showDialogRef = ref(false)
const value = ref('')
const tableData = ref([])
//加载加盟列表
const loadFranchise = async () => {
  const ret = await $franchise()
  tableData.value = ret.t
}
onMounted(() => {
  loadFranchise()
})
// 审核弹窗信息
const handleEdit = async (id:number) =>{
  const res = await $franchiseById({id})
  if(res.code === 4001){
    ElNotification({
      title: '失败！',
      message: '服务器异常，请联系管理员！',
      type: 'error',
    })
    return
  }
  dialogRef.value.examDialog = true
  dialogRef.value.formData = res.t
}
// 查看弹窗信息
const ShowHotelDialog = async (id: number) => {
  const res = await $franchiseById({id})
  if (res.code === 4001) {
    ElNotification({
      title: '失败！',
      message: '服务器异常，请联系管理员！',
      type: 'error',
    })
    return
  }
  showDialogRef.value.showDialog = true
  showDialogRef.value.showForm = res.t
}
</script>

<template>
  <ExamDialog ref="dialogRef"></ExamDialog>
  <ShowDialog ref="showDialogRef"></ShowDialog>
  <el-row :gutter="20" justify="start" align="middle">
    <el-col :span="4">
      <el-select
          v-model="value"
          filterable
          placeholder="审核查询"
          style="width: 240px"
      >
        <el-option label="请选择" value=""/>
        <el-option label="已通过" value="通过"/>
        <el-option label="未通过" value="未通过"/>
      </el-select>
    </el-col>
  </el-row>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column label="序号" prop="id" width="100"/>
    <el-table-column label="酒店名称" prop="hotel_name"/>
    <el-table-column label="酒店地址" prop="hotel_address"/>
    <el-table-column label="酒店联系人" prop="hotel_context"/>
    <el-table-column label="酒店联系人电话" prop="hotel_phone"/>
    <el-table-column label="审核员" prop="username"/>
    <el-table-column label="审核时间" prop="audit_time"/>
    <el-table-column label="审核状态" prop="audit_status"/>
    <el-table-column label="操作">
      <template #default="scope">
        <el-button
            v-if="scope.row.audit_status === '待审核'"
            size="middle"
            style="background-color: #ff6257;color: black"
            @click="handleEdit(scope.row.id)">审核
        </el-button>
        <el-button v-else size="middle" style="background-color: #2b86c5;color: black"
                   @click="ShowHotelDialog(scope.row.id)">查看
        </el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<style scoped lang="scss">

</style>